﻿using SqlSugar;
using System.Linq.Expressions;
using XieCan.Core.DTO;
using XieCan.Core.Entity;

namespace XieCan.Core.IReposity
{
  /// <summary>
  /// SqlSugar多租户仓库
  /// </summary>
  /// <typeparam name="TEntity">数据实体</typeparam>
  /// <typeparam name="TCreateModel">添加模型</typeparam>
  /// <typeparam name="TUpdateModel">修改模型</typeparam>
  /// <typeparam name="TListModel">查询列表结果模型</typeparam>
  /// <typeparam name="TSingleModel">查询数据结果模型</typeparam>
  public interface IBaseRepository<TEntity, TCreateModel, TUpdateModel, TListModel, TSingleModel>
    where TEntity : BaseEntity, new()
    where TCreateModel : BaseCreateModel, new()
    where TUpdateModel : BaseUpdateModel, new()
    where TListModel : BaseListModel, new()
    where TSingleModel : BaseSingleModel, new()
  {

    #region 添加数据
    Task<OperateResult<bool>> InsertAsync(TCreateModel entity, CancellationToken cancel = default);
    #endregion

    #region 删除数据
    /// <summary>
    /// 删除数据
    /// </summary>
    /// <param name="id">唯一标识</param>
    /// <param name="deletor">删除者Id</param>
    /// <param name="cancel"></param>
    /// <returns></returns>
    Task<OperateResult<bool>> DeleteAsync(Guid id, string? deletor, CancellationToken cancel = default);

    /// <summary>
    /// 删除数据
    /// </summary>
    /// <param name="where">查询条件</param>
    /// <param name="deletor">删除者Id</param>
    /// <param name="cancel"></param>
    /// <returns></returns>
    Task<OperateResult<bool>> DeleteAsync(Expression<Func<TEntity, bool>> where, string? deletor, CancellationToken cancel = default);
    #endregion

    #region 修改数据
    /// <summary>
    /// 修改数据
    /// </summary>
    /// <param name="model">修改对象</param>
    /// <param name="id">唯一标识</param>
    /// <param name="cancel"></param>
    /// <returns></returns>
    Task<OperateResult<bool>> UpdateAsync(Guid id, TUpdateModel model, CancellationToken cancel = default);

    /// <summary>
    /// 修改数据
    /// </summary>
    /// <param name="columns">更新的列</param>
    /// <param name="where">查询条件</param>
    /// <param name="cancel"></param>
    /// <returns></returns>
    Task<OperateResult<bool>> UpdateAsync(Expression<Func<TEntity, TEntity>> columns, Expression<Func<TEntity, bool>> where, CancellationToken cancel = default);

    #endregion

    #region 查询单个数据
    /// <summary>
    /// 获取单个数据
    /// </summary>
    /// <param name="id">唯一标识</param>
    /// <param name="cancel"></param>
    /// <returns></returns>
    Task<OperateResult<TSingleModel?>> GetAsync(Guid id, CancellationToken cancel = default);

    /// <summary>
    /// 获取单个数据
    /// </summary>
    /// <param name="where">查询条件</param>
    /// <param name="cancel"></param>
    /// <returns></returns>
    Task<OperateResult<TSingleModel?>> GetAsync(Expression<Func<TEntity, bool>> where, CancellationToken cancel = default);
    #endregion

    #region 获取分页数据
    /// <summary>
    /// 获取数据列表
    /// </summary>
    /// <param name="where">查询条件</param>
    /// <param name="cancel"></param>
    /// <returns></returns>
    Task<OperateResult<List<TListModel>>> GetListAsync(Expression<Func<TEntity, bool>> where, CancellationToken cancel = default);
    #endregion
  }
}